package io.renren.system.oss.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.renren.common.constant.Constant;
import io.renren.common.page.PageData;
import io.renren.common.service.impl.BaseServiceImpl;
import io.renren.system.oss.dao.SysOssDao;
import io.renren.system.oss.entity.SysOssEntity;
import io.renren.system.oss.service.SysOssService;
import io.renren.common.utils.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 【系统设置-文件上传】
 */
@Service
public class SysOssServiceImpl extends BaseServiceImpl<SysOssDao, SysOssEntity> implements SysOssService {

    private QueryWrapper<SysOssEntity> getWrapper(Map<String, Object> params) {
        String url = StringUtils.checkObj2Str(params.get("url"));
        QueryWrapper<SysOssEntity> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.isNotEmpty(url), "url", url);
        return wrapper;
    }

    /**
     * 根据查询条件分页获取文件上传列表数据
     *
     * @param params
     * @return
     */
    @Override
    public PageData<SysOssEntity> page(Map<String, Object> params) {
        IPage<SysOssEntity> page = baseDao.selectPage(
                getPage(params, Constant.CREATE_DATE, false),
                getWrapper(params)
        );
        return getPageData(page, SysOssEntity.class);
    }
}
